package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zzw.domain.RegionInfo;
import com.ruoyi.zzw.service.TRegionInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 地区管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/region")
public class BackRegionInfoController extends BaseController
{
    @Autowired
    private TRegionInfoService tRegionInfoService;

    /**
     * 查询地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:list')")
    @GetMapping("/list")
    public AjaxResult list(RegionInfo regionInfo)
    {
        List<RegionInfo> list = tRegionInfoService.selectTRegionInfoList(regionInfo);
        return success(list);
    }

    /**
     * 导出地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:export')")
    @Log(title = "地区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RegionInfo regionInfo)
    {
        List<RegionInfo> list = tRegionInfoService.selectTRegionInfoList(regionInfo);
        ExcelUtil<RegionInfo> util = new ExcelUtil<RegionInfo>(RegionInfo.class);
        util.exportExcel(response, list, "地区管理数据");
    }

    /**
     * 获取地区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:region:query')")
    @GetMapping(value = "/{cRegionId}")
    public AjaxResult getInfo(@PathVariable("cRegionId") Long cRegionId)
    {
        return success(tRegionInfoService.selectTRegionInfoByCRegionId(cRegionId));
    }

    /**
     * 新增地区管理
     */
    @PreAuthorize("@ss.hasPermi('system:region:add')")
    @Log(title = "地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegionInfo regionInfo)
    {
        return toAjax(tRegionInfoService.insertTRegionInfo(regionInfo));
    }

    /**
     * 修改地区管理
     */
    @PreAuthorize("@ss.hasPermi('system:region:edit')")
    @Log(title = "地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RegionInfo regionInfo)
    {
        return toAjax(tRegionInfoService.updateTRegionInfo(regionInfo));
    }

    /**
     * 删除地区管理
     */
    @PreAuthorize("@ss.hasPermi('system:region:remove')")
    @Log(title = "地区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cRegionIds}")
    public AjaxResult remove(@PathVariable Long[] cRegionIds)
    {
        return toAjax(tRegionInfoService.deleteTRegionInfoByCRegionIds(cRegionIds));
    }
}
